// pages/app/certification/study/study.js
const app = getApp();
var host = app.globalData.host;
var utils = app.globalData.utils;
var self = null;

Page({
  data: {
    themeColor: '',
    defaultColor: '',
    borderColor: '',
    certItemId: '',
    isVideo: false,
    videoUrl: '',
    list: [],
    current: 0
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
    self.setData({
      certItemId: options.id
    })
    self.init();
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  init() {
    var url = host + '/lx/mini/question/study';
    var params = {
      certificateItemId: self.data.certItemId
    };
    var success = function (res) {
      console.log(res);
      if (res.info.isVideo === 1) {
        self.setData({
          isVideo: true,
          videoUrl: res.info.url
        })
      } else {
        var list = res.info.list;
        if (!list || list.length == 0) {
          return;
        }
        list.reverse();
        self.setData({
          isVideo: false,
          list: list,
          current: list.length - 1
        })
      }
    }
    var fail = function (res) {
      console.log(res);
    };
    var complete = function () { };
    utils.request(url, params, success, fail, complete);
  }
})